/*
 * Square.cpp
 *
 *  Created on: Apr 29, 2012
 *      Author: kobe
 */

#include "Square.h"

Square::Square(std::string input) :
		Proposition(SQUARE) {
	std::string content(input, 2, input.size() - 2);
	size_t left, right;
	std::string sleft = getBracketContent(content, &left, &right);
	std::string ncontent(content, right + 2, content.size() - right - 2);
	std::string sright = getBracketContent(ncontent, &left, &right);
	mAgent = new Agent(sleft);
	mProposition = createProposition(sright);
	if (mProposition->isAction()) {
		mIsAction = true;
	} else {
		mIsAction = false;
	}
}

std::string Square::toString() {
	std::string result;
	result += "sq{";
	result += mAgent->getName();
	result += "}{";
	result += mProposition->toString();
	result += '}';
	return result;
}

Square::~Square() {
	// TODO Auto-generated destructor stub
}

Agent *Square::getAgent() const {
	return mAgent;
}

Proposition *Square::getProposition() const {
	return mProposition;
}

bool Square::compare(Proposition* p) {
	if (p->getPropName() != BLACKDIAMOND) {
		return false;
	} else {
		Square* s = (Square*) p;
		return this->mAgent->compare(s->getAgent())
				&& this->mProposition->compare(s->getProposition());
	}
}

std::string Square::toLatex() {
	std::string s(" \\square_{");
	s += mAgent->toLatex();
	s += "}";
	ModalLogic type = mProposition->getPropName();
	if (type == CONJUNCTION || type == DISJUNCTION || type == UPDATE
			|| type == AFTER || type == MONOID) {
		s += "(";
		s += mProposition->toLatex();
		s += ")";
	} else {
		s += mProposition->toLatex();
	}
	return s;
}

bool Square::isAction() {
	return mIsAction;
}
